package com.wanmait.happyheating.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.happyheating.pojo.Admin;
import com.wanmait.happyheating.mapper.AdminMapper;
import com.wanmait.happyheating.service.AdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.wanmait.happyheating.util.DateToTimestampUtils;
import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;


/**
 * <p>
 * 管理员表 服务实现类
 * </p>
 *
 * @author yuQianTao
 * @since 2021-05-13
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
    @Resource
    private AdminMapper adminMapper;
    /**
     * 获得所有的用户信息（多表关联）
     * @author yuQianTao
     * @since 2021-05-13
     */
    @Override
    public Admin getAdmin(Integer id) {
        Admin admin=adminMapper.getAdmin(id);
        return admin;
    }

    @Override
    public Admin findAdminByJurisdiction(Integer ordersinfoId) {
        return adminMapper.findAdminByJurisdiction(ordersinfoId);
    }

    /**
     * 分页查询所有管理员，按照姓名以及录入时间查询都是使用此方法
     * @author 王梓旭
     * @param admin 包含管理员姓名
     * @param date 页面上所选的添加时间
     * @param pageNum 页面数
     * @param pageSize 每页显示数量
     * @return pageInfo
     */
    @Override
    public PageInfo<Admin> findAllByPage(Admin admin, Date date, Integer pageNum, Integer pageSize) {
        //创建条件构造器，按需添加需要的查询条件
        LambdaQueryWrapper<Admin> queryWrapper = new LambdaQueryWrapper<>();
        if (null != admin){
            queryWrapper.like(Admin::getName,admin.getName());
        }
        if (null != date){
            //date类型转换为Timestamp类型
            Timestamp inputTime = DateToTimestampUtils.dateToTimestamp(date);

            queryWrapper.eq(Admin::getInputTime,inputTime);
        }

        //获取查询集合
        List<Admin> admins = adminMapper.selectList(queryWrapper);

        //处理页面页码相关参数
        if (null == pageNum){
            pageNum = 1;
        }
        if (null == pageSize ){

        }

        PageHelper.startPage(pageNum,pageSize);

        return null;
    }















}